import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vitePluginImport from 'vite-plugin-babel-import';
// import visualizer from "rollup-plugin-visualizer";
import path from 'path'

const baseUrl = {
  development: './',
  beta: './',
  release: './'
}
// 打包生产环境才引入的插件
// const visualizer_view = []
// if (process.env.NODE_ENV === "production") {
// if (process.env.vis) {
//   // 打包依赖展示
//   visualizer_view.push(
//       visualizer({
//           open: true,
//           gzipSize: true,
//           brotliSize: true,
//       })
//   );
// }
// https://vitejs.dev/config/
export default ({ mode }) =>  defineConfig({
  plugins: [
    vue(),
    vitePluginImport([
      {
        libraryName: 'element-plus',
        libraryDirectory: 'es',
        style(name) {
          return `element-plus/lib/theme-chalk/${name}.css`;
        },
      }
    ]),
    // ...visualizer_view
  ],
  base: baseUrl[mode],
  resolve: {
    alias: {
      '~': path.resolve(__dirname, './'),
      '@': path.resolve(__dirname, 'src'),
      '@api': path.resolve(__dirname, 'src/api'),
      '@components': path.resolve(__dirname, 'src/components'),
      '@utils': path.resolve(__dirname, 'src/utils'),
      '@views': path.resolve(__dirname, 'src/views')
    }
  },
  server: {
    port:8082, // 启动端口号
    open:true, // 启动后是否自动打开网页
    proxy: {
      '/manage-api/v1': {
        target: 'http://localhost:8888',
        changeOrigin: true,
        // rewrite: path => path.replace(/^\/api/, '/api/v1')
      }
    }
  }
})
